<?php
namespace app\common\model;

// use think\Model;

class Option extends \app\common\model\Base
{




    //系统支持自动写入创建和更新的时间戳字段
    // protected $autoWriteTimestamp = false;

    //类型自动转换
    protected $type = [
        'id'    =>  'integer',                 
        'pid'     =>  'integer',         
        'name'      =>  'string',         
        
    ];


    

    public function getOpts($pid= 0 ){
    		$option_list = cache('option_list');//缓存
			if (!$option_list) {
				$option_list =array();
				$rs = $this->select();
				foreach($rs as $k => $v ){
					$option_list[$v['pid']][$v['id']] = $v['name'];
				};
				cache('option_list',$option_list);//缓存
			}
			if( isset($pid) && isset( $option_list[$pid] ) ){
				return $option_list[$pid];
			}else{
				return [];
			}
    }

    public function cache_clear(){
    	cache('option_list',NULL);
    }



}